// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
using namespace std;

int main(int argc, char *argv[]) {

  string filenameoutput;
  string filenameinput;
  string line;
  filenameinput = (string(argv[1]).c_str());
  // if (filenameinput) return 0;

  ifstream infile (string(argv[1]).c_str());
  ofstream logfile ("log.txt");

  cout << "il nome del file passato e':" << filenameinput << endl;
  logfile << "File da splittare:" << filenameinput << "\n";

  if (infile.is_open())
  {
    while ( getline (infile,line) )
    {
        if (line.compare(0,8,"Filename") == 0) {
            // cout << line << " OK\n";
            filenameoutput=line.substr(9,999);
            cout << filenameoutput << "\n";
            logfile << filenameoutput << "\n";
            // ofstream outfilexml ("filenameoutput. ");
            ofstream outfilexml (string(filenameoutput).c_str());
            // outfilexml << line << "\n";
        } else {
                ofstream outfilexml (string(filenameoutput).c_str(),ios::app);
                outfilexml << line << "\n";
                outfilexml.close();
               }
    }
    infile.close();

  }

  else logfile << "File da splittare: " << filenameinput << " non trovato!!!";

  return 0;
}

